package com.mujin.keji.collectionsystem.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.ScrollView;

/**
 * Created by daxiaa on 2017/9/20.
 */

public class CustomerScrollView extends ScrollView {
    private int mTouchSlop;
    private int lastX;
    private int lastY;

    public CustomerScrollView(Context context) {
        super(context);

    }

    public CustomerScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        int x = (int) event.getRawX();
        int y = (int) event.getRawY();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastX = x;
                lastY = y;
                break;
            case MotionEvent.ACTION_MOVE:
                int deltaY = y - lastY;
                int deltaX = x - lastX;
                if (Math.abs(deltaY) > mTouchSlop && Math.abs(deltaY) > Math.abs(deltaX)) {
                    return true;
                } else {
                    return false;
                }
            default:
                break;
        }
        return super.onInterceptTouchEvent(event);
    }
}
